clc;
close all;
clear all;

%%RD1
eredge95_rd1 = importdata('PRKS95_eredge_rd1.txt');
K95_rd1 = CalculateK(eredge95_rd1);
eredge90_rd1 = importdata('PRKS90_eredge_rd1.txt');
K90_rd1 = CalculateK(eredge90_rd1);
eredge80_rd1 = importdata('PRKS80_eredge_rd1.txt');
K80_rd1 = CalculateK(eredge80_rd1);
eredge70_rd1 = importdata('PRKS70_eredge_rd1.txt');
K70_rd1 = CalculateK(eredge70_rd1);

%%RD2
eredge95_rd2 = importdata('PRKS95_eredge_rd2.txt');
K95_rd2 = CalculateK(eredge95_rd2);
eredge90_rd2 = importdata('PRKS90_eredge_rd2.txt');
K90_rd2 = CalculateK(eredge90_rd2);
eredge80_rd2 = importdata('PRKS80_eredge_rd2.txt');
K80_rd2 = CalculateK(eredge80_rd2);
eredge70_rd2 = importdata('PRKS70_eredge_rd2.txt');
K70_rd2 = CalculateK(eredge70_rd2);

%%RD3
eredge95_rd3 = importdata('PRKS95_eredge_rd3.txt');
K95_rd3 = CalculateK(eredge95_rd3);
eredge90_rd3 = importdata('PRKS90_eredge_rd3.txt');
K90_rd3 = CalculateK(eredge90_rd3);
eredge80_rd3 = importdata('PRKS80_eredge_rd3.txt');
K80_rd3 = CalculateK(eredge80_rd3);
eredge70_rd3 = importdata('PRKS70_eredge_rd3.txt');
K70_rd3 = CalculateK(eredge70_rd3);

%%RD4
eredge95_rd4 = importdata('PRKS95_eredge_rd4.txt');
K95_rd4 = CalculateK(eredge95_rd4);
eredge90_rd4 = importdata('PRKS90_eredge_rd4.txt');
K90_rd4 = CalculateK(eredge90_rd4);
eredge80_rd4 = importdata('PRKS80_eredge_rd4.txt');
K80_rd4 = CalculateK(eredge80_rd4);
eredge70_rd4 = importdata('PRKS70_eredge_rd4.txt');
K70_rd4 = CalculateK(eredge70_rd4);


%%RD5
eredge95_rd5 = importdata('PRKS95_eredge_rd5.txt');
K95_rd5 = CalculateK(eredge95_rd5);
eredge90_rd5 = importdata('PRKS90_eredge_rd5.txt');
K90_rd5 = CalculateK(eredge90_rd5);
eredge80_rd5 = importdata('PRKS80_eredge_rd5.txt');
K80_rd5 = CalculateK(eredge80_rd5);
eredge70_rd5 = importdata('PRKS70_eredge_rd5.txt');
K70_rd5 = CalculateK(eredge70_rd5);

K95 = [K95_rd1; K95_rd2;K95_rd3;K95_rd4;K95_rd5];
K90 = [K90_rd1; K90_rd2;K90_rd3;K90_rd4;K90_rd5];
K80 = [K80_rd1; K80_rd2;K80_rd3;K80_rd4;K80_rd5];
K70 = [K70_rd1; K70_rd2;K70_rd3;K70_rd4;K70_rd5];

result = {0};
result{1} = K70(:,3);
result{2} = K80(:,3);
result{3} = K90(:,3);
result{4} = K95(:,3);

group = zeros(0);
dataDisp = zeros(0);
for i = 1 : size(result, 2)
    group = [group ; ones(size(result{i})) + i - 1];
    dataDisp = [dataDisp ; result{i}];
end
figure3 = figure;
boxplot(dataDisp, group, 'notch', 'on');hold on
set(gca,'xtick',[1 2 3 4],'xticklabel',{'70%','80%','90%','95%'},'fontsize',60);
xlabel('PDR', 'FontSize', 30);
ylabel('PRK parameter', 'FontSize', 30);
grid on;
set(gca,'fontsize',30,'YScale','log');
maximize ();
%saveas (gcf, 'boxplot_diff_pdr_req_k_light.fig')
%saveas (gcf, 'boxplot_diff_pdr_req_k_light.eps')
%saveas (gcf, 'boxplot_diff_pdr_req_k_light.jpg')


result = {0};
result{1} = 10*log10(K70(:,3));
result{2} = 10*log10(K80(:,3));
result{3} = 10*log10(K90(:,3));
result{4} = 10*log10(K95(:,3));

group = zeros(0);
dataDisp = zeros(0);
for i = 1 : size(result, 2)
    group = [group ; ones(size(result{i})) + i - 1];
    dataDisp = [dataDisp ; result{i}];
end
figure4 = figure;
boxplot(dataDisp, group, 'notch', 'on');hold on
set(gca,'xtick',[1 2 3 4],'xticklabel',{'70%','80%','90%','95%'},'fontsize',60);
xlabel('PDR', 'FontSize', 30);
ylabel('PRK parameter (dB)', 'FontSize', 30);
grid on;
%set(gca,'fontsize',60,'YScale','log');
set(gca,'fontsize',30);
maximize ();
%saveas (gcf, 'boxplot_diff_pdr_req_k_in_dB_light.fig')
%saveas (gcf, 'boxplot_diff_pdr_req_k_in_dB_light.eps')
%saveas (gcf, 'boxplot_diff_pdr_req_k_in_dB_light.jpg')

